Skip to content

fix: propagate context at MCP server #1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

CakeCrusher
Copy link
Contributor

TLDR:
The context passed by the InstrumentedStreamWriter.send was being mutated by processes preceeding InstrumentedStreamReader resulting in disjointed MCP traces.
image
By adding instrumentation at _handle_request (an earlier state in the program flow) the original message composed by InstrumentedStreamWriter.send is preserved. This context is then propagated at the server level.
image

the context is detached by the same method it was being detached before, through InstrumentedStreamReader.

@CakeCrusher CakeCrusher requested a review from a team as a code owner May 20, 2025 05:58
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 20, 2025
@CakeCrusher CakeCrusher force-pushed the fix_mcp_ctx_propagation branch from f88a4d3 to d9068a1 Compare May 20, 2025 06:28
@CakeCrusher CakeCrusher force-pushed the fix_mcp_ctx_propagation branch from d9068a1 to e955392 Compare May 20, 2025 06:36
@caroger caroger requested a review from mikeldking May 20, 2025 17:50
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 20, 2025
caroger and others added 3 commits May 21, 2025 23:09
Co-authored-by: Mikyo King <mikeldking@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels May 22, 2025
@CakeCrusher
Copy link
Contributor Author

Have not tested multiplexing, so it may be vulnerable to that.
(Testing this seems pretty complex which is why I have not written any tests yet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants